<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box{
            width: 100%;
        }
        .box1{
            width: 100%;
            height: 50px;
            background: lavender;
        }
        .btn{
            background: orange;
            color: white;
            border: 0;
            width: 80px;
            height: 30px;
            border-radius: 5px;
        }
        .liang{
            background: crimson;
            color: white;
            border: 0;
            width: 100px;
            height: 30px;
            line-height: 30px;
            border-radius: 5px;
            margin: 10px;
        }
        .sou{
            width: 150px;
            height: 20px;
            border-radius: 3px;
            margin: 10px;
        }
        table{
            margin-top: 15px;
            width: 100%;
            border-collapse: collapse;
            text-align: center;
        }
        th{
            border: 1px solid silver;
        }
        th:active{color: red}
        th:hover{color: red}
        td{
            border: 1px solid silver;
        }
            .kuang{
                margin-left:13%;
                font-family: 宋体;
                font-size: 14px;
                font-weight:bold;
            }
        .lyy{
            width: 1000px;
            height: 30px;
            margin-top: 22%;
            margin-left: 48%;
        }
        .sb{
            border: 0;
            background: #2D93CA;
            margin-top: -3px;
            width: 70px;
            height: 30px;
            border-radius: 5px;
        }
        .zhuan1{
            width: 50px;
            height: 20px;
        }
        .zhuan2{
            border: solid;
            color: #2D93CA;
            font-weight: bold;
            font-size: 20px;
            background: transparent;

            border: 0;
        }
        .dao{
            font-family: 黑体;
            font-size: 17px;
        }
        .touxinxi{
            font-size: 14px;
        }
        .nei{
            margin-left: 450px;
        }
    </style>
    <script src="/resources/js/jquery-1.7.1.min.js" type="application/javascript"></script>
    <script src="/resources/js/jquery-ui-1.8.10.custom.min.js" type="text/css"></script>
</head>

            <script>
                $(function () {

                    $(document).ready(function () {
                        var time = new Date();
                        var day = ("0" + time.getDate()).slice(-2);
                        var month = ("0" + (time.getMonth() + 1)).slice(-2);
                        var today = time.getFullYear() + "-" + (month) + "-" + (day);
                        $('#date_info').val(today);
                    });
                    $.getJSON("/selectCategory",{},function (data) {
                        var leibie = '<option value="">全部</option>';
                        for(var i = 0 ;i < data.length;i++){
                            var lei = data[i];
                            leibie +='<option value="'+lei.id+'">'+lei.category+'</option>'
                        }
                        $("#leibie").append(leibie);
                    })

                    $.getJSON("/selectProviderIdName",{},function (data) {
                        var gonghuoshang = '<option value="">全部</option>';
                        for(var i = 0 ;i < data.length;i++){
                            var zhi = data[i];
                            gonghuoshang +='<option value="'+zhi.id+'">'+zhi.providerName+'</option>'
                        }
                        $("#gonghuoshang").append(gonghuoshang);
                    })
                    readList(1);
                    zhanShi(1);
                });


                var da = "";
                function readList(pageNum) {
                    if(pageNum == 0){
                        pageNum = 1;
                    }
                    var form = $("#form1")[0];
                    var formData= new FormData(form);
                    var Sid = location.href.split("=")[1];
                    formData.append("closeId",Sid);
                    formData.append("hospitalId",1);
                    formData.append("pageNum",pageNum);
                    $.ajax({
                        url:"/selectClearing",
                        data:formData,
                        dataTpe:"json",
                        type:"post",
                        processData:false,
                        contentType:false,
                        success:function (data) {
                            da = data;
                            var table = '';
                            var list = data.list;
                            $("#table").empty();
                            for(var i = 0; i < list.length;i++){
                                var zhi = list[i];
                                table += '<tr>' +
                                    '<td>'+zhi.id+'</td>'+
                                    '<td><input type="checkbox" class="checkMin" value="'+zhi.id+'" onclick="checkMin()"/></td>' +
                                    '<td>'+zhi.purchaseNum+'</td>'+
                                    '<td>'+zhi.purchaseName+'</td>'+
                                    '<td>'+zhi.hospitalName+'</td>'+
                                    '<td>'+zhi.serialNumber+'</td>'+
                                    '<td>'+zhi.commonName+'</td>'+
                                    '<td>'+zhi.commodityName+'</td>'+
                                    '<td>'+zhi.winPrice+'</td>'+
                                    '<td>'+zhi.trading+'</td>'+
                                    '<td>'+zhi.purchaseAmount+'</td>'+
                                    '<td>'+zhi.purchasePrice+'</td>'+
                                    '<td>'+zhi.inputNum+'</td>'+
                                    '<td>'+zhi.inputPrice+'</td>'+
                                    '<td>'+zhi.invoiceNum+'</td>'+
                                    '<td>'+zhi.batchNumber+'</td>'+
                                    '<td>'+zhi.drugTime+'</td>'+
                                    '<td>'+zhi.closeNum+'</td>'+
                                    '<td>'+zhi.closePrice+'</td>'+
                                    '<td>'+zhi.dosageForm+'</td>'+
                                    '<td>'+zhi.size+'</td>'+
                                    '<td>'+zhi.unit+'</td>'+
                                    '<td>'+zhi.factor+'</td>'+
                                    '<td>'+zhi.zhiliangcengci+'</td>'+
                                    '<td>'+zhi.productionName+'</td>'+
                                    '<td>'+zhi.providerName+'</td>'+
                                    '<td>'+zhi.createTime+'</td>'+
                                    '<td>'+zhi.overTime+'</td>'+
                                    '<td>'+zhi.jiesuanzhuangtai+'</td>'+
                                    '</tr>';
                            }
                            $("#table").append(table);
                        }
                    })
                }
                
                function jian() {
                    var x = $("input[name='zhuan']").val();
                    readList(x);
                }

                function checkMax() {
                    var check=$(".checkMax").prop("checked");
                    $(".checkMin").prop('checked',check);
                }
                function checkMin() {
                    var chec=true;
                    $.each($(".checkMin"),function (index,item) {
                        if($(item).prop("checked")==false){
                            chec=false;
                        }
                    })
                    $(".checkMax").prop('checked',chec);
                }

                function AddDrug(){
                    var Sid = location.href.split("id=")[1];
                    alert(Sid)
                    /*location.href="="+Sid;*/
                }
                
                function zhanShi() {
                    var Sid = location.href.split("=")[1];
                    $.ajax({
                        url:"/selectFinalParticulars",
                        data:{id:Sid},
                        dataType:"json",
                        type:"post",
                        success:function (data) {
                            $("input[name='hospitalId']").val(data[0].hospitalId);
                            $("input[name='hospitalName2']").val(data[0].hospitalName);
                            $("input[name='closeNum']").val(data[0].closeNum);
;                            $("input[name='closeName']").val(data[0].closeName);
                            $("input[name='linkman']").val(data[0].linkman);
                            $("input[name='linkphone']").val(data[0].linkphone);
                            $("input[name='closeState']").val(data[0].dataName);
                            var date = data[0].createTime;
                            $("#createTime").val(date.substring(0,10));
                            var date2 = data[0].submitTime;
                            $("#submitTime").val(date2.substring(0,10));
                            $("input[name='remark']").val(data[0].remark);


                        }
                    })
                }

                function baoCunJieSuanDan() {
                    if($("input[name='closeState']").val() == "已确认结算"){
                        alert("结算单已提交，无法保存！")
                        return;
                    }else{
                        alert("保存成功！");
                        readList(1);
                    }
                }
                
                function tijiaoJieSuanDan() {
                    if($("input[name='closeState']").val() == "已确认结算"){
                        alert("结算单已提交，无法重复提交！")
                        return;
                    }else{
                        confirm("提交成功，该结算单信息一经提交将无法修改！");
                    }
                    var Sid = location.href.split("=")[1];
                    $.ajax({
                        url:"/updateCloseState",
                        data:{id:Sid},
                        dataType:"json",
                        type:"post",
                        success:function (data) {
                            window.location.reload()//刷新页面
                        }
                    })
                }

                function deleteJieSuanYaoPingXinXi() {
                    var idList = new Array();
                    $.each($(".checkMin"),function (index,item) {
                        if($(item).prop("checked")==true){
                            idList.push($(item).val());
                        }
                    });
                    if(idList != 0){
                        if($("input[name='closeState']").val() == "已确认结算"){
                            alert("删除失败！结算单已提交，无法修改已提交的结算单信息。")
                            return;
                        }
                    }else{
                        alert("请勾选需要删除的信息！");
                        return;
                    }
                    $.ajax({
                        url:"/deleteFinalDrug",
                        data:{idList:idList},
                        dataType:"json",
                        type:"post",
                        traditional: true,
                        success:function (data) {
                            alert("成功删除"+data+"条数据！！！");
                            readList(1);
                        }
                    })
                }
            </script>
<body>
<div class="box">
    <h3>添加结算单药品</h3>
    <hr/>
    <div class="nei">
        <form action="" method="post" id="form2">
            &nbsp;&nbsp;
            医院编号：
            <input type="text" class="sou" id="hospitalId" name="hospitalId" readonly="readonly" >
            &nbsp;&nbsp;
            医院名称：
            <input type="text" class="sou" id="hospitalName" name="hospitalName2" readonly="readonly">
            <br/>
            结算单编号：
            <input type="text" class="sou" id="closeNum" name="closeNum" readonly="readonly">
            结算单名称：
            <input type="text" class="sou" id="closeName" name="closeName" readonly="readonly" >
            <br/>
            &nbsp;&nbsp;
            结算时间：
            <input type="date" class="sou" id="date_info" readonly="readonly">
            &nbsp;&nbsp;&nbsp;
            建单时间：
            <input type="date" class="sou" id="createTime" name="createTime" readonly="readonly" >
            <br/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            联系人：
            <input type="text" class="sou" id="linkman" name="linkman" readonly="readonly">
            &nbsp;&nbsp;
            联系电话：
            <input type="text" class="sou" id="linkphone" name="linkphone" readonly="readonly">
            <br/>
            结算单状态：
            <input type="text" class="sou" value="" name="closeState" readonly="readonly">
            &nbsp;&nbsp;
            提交时间：
            <input type="date" class="sou" id="submitTime" name="submitTime" readonly="readonly">
            <br/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            备注：
            <input type="text" id="remark" class="sou" name="remark" style="width: 300px" readonly="readonly">
            <br/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="submit" class="danzi" value="保存结算单" onclick="baoCunJieSuanDan();return false;" style="height: 30px;width: 160px;background-color:#2D93CA">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="submit" class="danzi" value="提交结算单" onclick="tijiaoJieSuanDan();return false;" style="height: 30px;width: 160px;background-color:#2D93CA">
        </form>
    </div>
    <hr>
    <form action="" method="post" id="form1">
    <div class="kuang">
        &nbsp;
        采购单编号:
        <input type="text" placeholder="输入采购单编号" class="sou" name="purchaseNum"/>
        &nbsp;
        采购单名称:
        <input type="text" placeholder="输入采购单名称" class="sou" name="purchaseName"/>

        结算状态：
        <select type="text"class="sou" id="caigouzhuangtai" name="purchaseState">
            <option value="">全部</option>
            <option value="1">未确认结算</option>
            <option value="2">已确认结算</option>
        </select>
        采购医院:
        <input type="text" placeholder="输入采购医院" class="sou" name="hospitalName"/>
        <br/>
        开始采购时间：
        <input type="date" class="sou" name="createTime">
        结束采购时间：
        <input type="date" class="sou" name="overTime">
        药品流水号:
        <input type="text" placeholder="输入药品流水号" class="sou" name="serialNumber"/>
        通用名：
        <input type="text" placeholder="输入通用名" class="sou" name="commonName"/>
        <br/>
        &nbsp;&nbsp;&nbsp;
        剂型：
        <input type="text" placeholder="输入剂型" class="sou" name="dosageForm"/>
        &nbsp;&nbsp;&nbsp;&nbsp;
        规格:
        <input type="text" placeholder="输入规格" class="sou" name="size"/>
        &nbsp;&nbsp;
        单位：
        <input type="text" placeholder="输入单位" class="sou" name="unit"/>
        转换系数:
        <input type="text" placeholder="输入转换系数" class="sou" name="factor"/>
        <br/>
        &nbsp;
        生产企业：
        <input type="text" placeholder="输入生产企业" class="sou" name="productionName"/>
        &nbsp;&nbsp;&nbsp;
        商品名:
        <input type="text" placeholder="输入商品名" class="sou" name="commodityName"/>
        &nbsp;
        质量层次:
        <select class="sou" id="" name="quality">
            <option value="">全部</option>
            <option value=1>国家一类新药</option>
            <option value=2>国家科学进步奖</option>
            <option value=3>专利</option>
            <option value=4>原研</option>
            <option value=5>单独定价</option>
            <option value=6>优质优价</option>
            <option value=7>GMP</option>
        </select>
        药品类别:
        <select class="sou" id="leibie" name="category">

        </select>
        <br/>
        入库时间:
        <input type="date" class="sou" name="inputTimeMin" style="width: 100px">至<input type="date" class="sou" name="inputTimeMax" style="width: 100px">
        药品批号：
        <input type="text" placeholder="输入药品批号" class="sou" name="batchNumber"/>
        发票号：
        <input type="text" placeholder="输入发票号" class="sou" name="invoiceNum"/>
        供货商：
        <select class="sou" id="gonghuoshang" name="providerId">

        </select>

    </div>
    </form>
</div>
<div class="box1">
    &nbsp;&nbsp;&nbsp;&nbsp;
    <button class="liang" onclick="AddDrug()" style="width: 150px">添加药品到退货单</button>
    &nbsp;&nbsp;&nbsp;
    <button class="liang" onclick="deleteJieSuanYaoPingXinXi()" style="width: 100px">删除</button>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;<button class="liang" onclick="readList(1)">查询</button>
</div>
<table>
    <thead class="touxinxi">
    <tr>
        <th>序号</th>
        <th><input type="checkbox" class="checkMax" onclick="checkMax()"/>选择</th>
        <th>采购单编号</th>
        <th>采购单名称</th>
        <th>采购医院</th>
        <th>流水号</th>
        <th>通用名</th>
        <th>商品名</th>
        <th>中标价</th>
        <th>交易价</th>
        <th>采购量</th>
        <th>采购金额</th>
        <th>入库量</th>
        <th>入库金额</th>
        <th>发票号</th>
        <th>药品批号</th>
        <th>药品有限期</th>
        <th>结算量</th>
        <th>结算金额</th>
        <th>剂型</th>
        <th>规格</th>
        <th>单位</th>
        <th>转换系数</th>
        <th>质量层次</th>
        <th>生产企业</th>
        <th>供货企业</th>
        <th>开始采购时间</th>
        <th>结束采购时间</th>
        <th>结算状态</th>
    </tr>
    </thead>
    <tbody id="table">

    </tbody>
</table>
<div class="lyy" style="margin: 10px">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(1)">首页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(da.prePage)">上一页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(da.nextPage)">下一页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(da.pages)">尾页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span class="dao">转到</span><input class="zhuan1" name="zhuan" type="text"><span class="dao">页</span><button class="zhuan2"><span class="jian" onclick="jian()">⇨</span></button>
</div>
</body>
</html>
